package com.mall.dw.controller;

import com.mall.common.util.RespResult;
import com.mall.dw.model.HotGoods;
import com.mall.dw.service.IHotGoodsService;
import com.mall.dw.util.DruidPage;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author Darren
 * @date 2022-10-14 9:50
 * Description：
 */
@RestController
@RequestMapping("/hot/goods")
public class HotGoodsController {
    @Autowired
    private IHotGoodsService hotGoodsService;

    @GetMapping("/list")
    @ApiOperation("查询所有")
    public RespResult<List<HotGoods>> list() {
        return RespResult.ok(hotGoodsService.list());
    }

    @GetMapping("/topNum/{size}")
    @ApiOperation("查询前N条记录")
    public RespResult<List<HotGoods>> topNum(@PathVariable("size") Integer size) {
        return RespResult.ok(hotGoodsService.topNum(size));
    }

    @GetMapping("/page/{page}/{size}")
    @ApiOperation("分页查询")
    public RespResult<DruidPage<List<HotGoods>>> pageList(@PathVariable("page") Integer page, @PathVariable("size") Integer size) {
        return RespResult.ok(hotGoodsService.pageList(page, size));
    }

    @GetMapping("/page/{page}/{size}/{sort}/{sortType}")
    @ApiOperation("分页查询(排序)")
    public RespResult<DruidPage<List<HotGoods>>> pageListSort(@PathVariable("page") Integer page, @PathVariable("size") Integer size,
                                                              @PathVariable("sort") String sort, @PathVariable("sortType") String sortType) {
        return RespResult.ok(hotGoodsService.pageListSort(page, size, sort, sortType));
    }

    @GetMapping("/list/{size}/{hour}")
    @ApiOperation("查询历史数据")
    public RespResult<List<HotGoods>> listByTime(@PathVariable("size") Integer size, @PathVariable("hour") Integer hour) {
        return RespResult.ok(hotGoodsService.listByTime(size, hour));
    }

    @PostMapping("/list/{size}/{hour}")
    @ApiOperation("查询历史数据")
    public RespResult<List<HotGoods>> listByTimeAndExclude(@PathVariable("size") Integer size, @PathVariable("hour") Integer hour,
                                                           @RequestBody String[] urls) {
        return RespResult.ok(hotGoodsService.listByTimeAndExclude(size, hour, urls));
    }

    @PostMapping("/list/{size}/{hour}/{max}")
    @ApiOperation("热门商品查询")
    public RespResult<List<Map<String, String>>> searchHotGoods(@PathVariable("size") Integer size, @PathVariable("hour") Integer hour,
                                                          @RequestBody String[] urls, @PathVariable("max") Integer max) {
        return RespResult.ok(hotGoodsService.searchHotGoods(size, hour, urls, max));
    }
}
